import { Component, OnInit, Injector, ViewChild } from '@angular/core';
import { DataDictionaryService } from 'services';
import { AppComponentBase } from '@shared/component-base/app-component-base';

@Component({
  selector: 'app-datadictionary',
  templateUrl: './datadictionary.component.html',
  styles: [],
  providers: [DataDictionaryService],
})
export class DatadictionaryComponent extends AppComponentBase
  implements OnInit {

  groupTypes = [];
  selectGroup: any;
  groupType: any;

  //@ViewChild("dataList") dataList: DataListComponent;

  constructor(
    injector: Injector,
    private dataDictionaryService: DataDictionaryService,
  ) {
    super(injector);
  }

  ngOnInit() {
    this.getGroupTypes();
  }

  getGroupTypes() {
    this.dataDictionaryService.getDataTypes().subscribe((result) => {
      this.groupTypes = result;
      if (this.groupTypes.length > 0) {
        this.groupType = this.groupTypes[0].name;
      }
    });
  }

  onGroupSelected(group: any) {
    //this.dataList.group = group;
    //this.dataList.refresh();
    this.selectGroup = group;
  }

  onSelectChange(tab: any) {
    //console.log(tab.index);
    this.groupType = this.groupTypes[tab.index].name;
  }
}
